<template>
  <div class="article">
    <van-list
      :loading="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="getList"
    >
      <van-cell
        v-for="(item, i) in list"
        :key="i"
        :to="{ name: 'Article', params: { id: item.id, article: item } }"
      >
        <div class="cell-header">
          <van-image
            width="1rem"
            height="1rem"
            fit="contain"
            :src="
              item.original_status.user.photo_domain +
              item.original_status.user.profile_image_url.split(',')[0]
            "
          />
          <div class="header-right">
            <div class="name">{{ item.original_status.user.screen_name }}</div>
            <div class="time">{{ item.original_status.timeBefore }}</div>
          </div>
        </div>
        <div
          class="cell-content"
          v-html="item.original_status.description"
        ></div>
        <div class="cell-footer">
          <div class="item">
            <van-icon name="share-o" />
            <div class="number">{{ item.original_status.retweet_count }}</div>
          </div>
          <div class="item">
            <van-icon name="smile-comment-o" />
            <div class="number">{{ item.original_status.reply_count }}</div>
          </div>
          <div class="item">
            <van-icon name="good-job-o" />
            <div class="number">{{ item.original_status.like_count }}</div>
          </div>
        </div>
      </van-cell>
    </van-list>
  </div>
</template>

<script>
import * as api from "@/api/index.js";
export default {
  data() {
    return {
      page: 1,
      list: [],
      finished: false,
      loading: false,
    };
  },
  methods: {
    async getList() {
      let res = await api.getArticles({ page: this.page });
      //   console.log(res);
      this.loading = false;
      if (res.result && res.result.indexOf("加载完") !== -1) {
        this.finished = true;
      } else {
        this.list = this.list.concat(res.items);
        this.page++;
      }
    },
  },
  //   async mounted() {
  //     this.getList();
  //   },
};
</script>

<style lang="less" scoped>
.article {
  .cell-header {
    margin-bottom: 0.3rem;
    display: flex;
    gap: 0.5rem;
    .header-right {
      font-size: 0.3rem;
      line-height: 0.5rem;
      .time {
        color: #999;
      }
    }
  }
  .cell-footer {
    margin-top: 0.2rem;
    display: flex;
    justify-content: space-around;
    align-items: center;
    .item {
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 0.2rem;
    }
  }
  .finish {
    color: #bbb;
    height: 0.8rem;
    line-height: 0.8rem;
    font-size: 0.4rem;
    text-align: center;
    background-color: #efefef;
  }
}
</style>
